﻿namespace Sidvall.LogManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class LogContext : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.LogManager.Data.ILogContext
    {
        #region Public Members

        #region Category

        private string _Category;
        partial void OnBeforeCategoryPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterCategoryPropertyChanged();
        public string Category
        { 
            get
            {
                return _Category;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Category = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Category);
                    OnBeforeCategoryPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Category", eventData.Value, true, true);
                        OnAfterCategoryPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region Content

        private string _Content;
        partial void OnBeforeContentPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterContentPropertyChanged();
        public string Content
        { 
            get
            {
                return _Content;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Content = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Content);
                    OnBeforeContentPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Content", eventData.Value, true, true);
                        OnAfterContentPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region EventTypeId

        private System.Nullable<global::Sidvall.Logging.EventType> _EventTypeId;
        partial void OnBeforeEventTypeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<global::Sidvall.Logging.EventType>> eventData);
        partial void OnAfterEventTypeIdPropertyChanged();
        public System.Nullable<global::Sidvall.Logging.EventType> EventTypeId
        { 
            get
            {
                return _EventTypeId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _EventTypeId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<global::Sidvall.Logging.EventType>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<global::Sidvall.Logging.EventType>>(value, _EventTypeId);
                    OnBeforeEventTypeIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("EventTypeId", eventData.Value, true, true);
                        OnAfterEventTypeIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region LogContextId

        private System.Nullable<int> _LogContextId;
        partial void OnBeforeLogContextIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterLogContextIdPropertyChanged();
        public System.Nullable<int> LogContextId
        { 
            get
            {
                return _LogContextId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _LogContextId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _LogContextId);
                    OnBeforeLogContextIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("LogContextId", eventData.Value, true, true);
                        OnAfterLogContextIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.LogContextManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.LogContextManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.LogContextManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public LogContext Copy()
        {
            return global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.LogContextManager.Copy(this);
        }
        public LogContext Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.LogContextManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.LogManager.Data.ILogContext item)
        {
            global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.LogContextManager.Import(this, item);
        }
        public void Import(global::Sidvall.LogManager.Data.ILogContext item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.LogContextManager.Import(this, item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.LogContextManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.LogContextManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.LogContextManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.LogContextManager.Initialize(this, settings);
        }

        #endregion

        #region ILogContext Members

        string global::Sidvall.LogManager.Data.ILogContext.Category
        {
            get
            {
                return this._Category;
            }
            set
            {
                this._Category = value;
            }
        }
        string global::Sidvall.LogManager.Data.ILogContext.Content
        {
            get
            {
                return this._Content;
            }
            set
            {
                this._Content = value;
            }
        }
        System.Nullable<global::Sidvall.Logging.EventType> global::Sidvall.LogManager.Data.ILogContext.EventTypeId
        {
            get
            {
                return this._EventTypeId;
            }
            set
            {
                this._EventTypeId = value;
            }
        }
        System.Nullable<int> global::Sidvall.LogManager.Data.ILogContext.LogContextId
        {
            get
            {
                return this._LogContextId;
            }
            set
            {
                this._LogContextId = value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public LogContext()
        {
        }
        public LogContext(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public LogContext(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.LogContextManager.Initialize(this);
        }

        #endregion
    }
}